package com.springboot.demo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wubc683
 * @desc
 * @date 2021-08-23 15:54
 */
public class DateUtils {
    /**
     * 时间格式(yyyy-MM-dd HH:mm:ss)
     */
    public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static String format(Date date) {
        if (date != null) {
            SimpleDateFormat df = new SimpleDateFormat(DATE_TIME_PATTERN);
            return df.format(date);
        }
        return null;
    }
    public static Date parse(String date) throws ParseException {
        if(date != null){
            SimpleDateFormat df = new SimpleDateFormat(DATE_TIME_PATTERN);
            return df.parse(date);
        }
        return null;
    }
}